<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //定义一个Person
    let Person = function () {}
        //等效创建Person.java 里面什么都不写
        //实例化对象
        let p = new Person();
        //在JS中可以动态的给实例化的对象添加属性和方法
        p.name = "张三";
        p.age = 18;
        p.run = function () {
            alert(this.name)
        }
       // p.run()

        //直接实例化对象
    let hero = {
            name:"孙悟空",
            age:500,
        run:function () {
alert(this.name)
        }
    };
        hero.run();

        let arr = [{name:"孙悟空", age:500},
    {name:"八戒", age:300},
    {name:"悟净", age:400}
    ];
    for(let i= 0 ; i<arr.length;i++){
        let h= arr[i];
        alert(h.name+":"+h.age);
    }
</script>
</body>
</html>